<template>
    <div class="asset-card-wrapper">
        <div class="asset-card" v-if="currentTab == 'pdzc'">
            <div class="asset-name">{{ asset.propertyName }}</div>

            <!-- 状态1：盘点状态 -->
            <div class="status-section">
                <div class="status-header">
                    <van-icon name="clock-o" size="16" color="#666" />
                    <span class="status-text">{{ tasktype(asset.stocktakingResult) }}</span>
                </div>
                <div class="status-detail">
                    <div class="status-item">
                        <div class="double-icon-small">
                            <van-icon name="friends-o" size="14" color="#999" />
                        </div>
                        <span class="status-value">{{ asset.stocktakingPersonName || '--' }}</span>
                    </div>
                    <div class="status-item">
                        <van-icon name="clock-o" size="14" color="#999" />
                        <span class="status-value">{{ formatDT(asset.stocktakingDate) || '--' }}</span>
                    </div>
                </div>
            </div>

            <!-- 状态2：复核状态 -->
            <div class="status-section">
                <div class="status-header">
                    <van-icon name="passed" size="16" color="#666" />
                    <span class="status-text">{{ reviewtype(asset.reviewResult) || '--' }}</span>
                </div>
                <div class="status-detail">
                    <div class="status-item">
                        <div class="double-icon-small">
                            <van-icon name="friends-o" size="14" color="#999" />
                            <!-- <van-icon name="friends-o" size="14" color="#999" class="icon-overlap-small" /> -->
                        </div>
                        <span class="status-value">{{ asset.reviewPersonName || '--' }}</span>
                    </div>
                    <div class="status-item">
                        <van-icon name="clock-o" size="14" color="#999" />
                        <span class="status-value">{{ formatDT(asset.reviewDate) || '--' }}</span>
                    </div>
                </div>
            </div>

            <div class="action-buttons">
                <van-button v-if="showDetail" plain color="#999" class="action-btn" size="small" @click="$emit('detail', asset)"> 详情 </van-button>
                <van-button v-if="showLoss" color="#3772ff" class="action-btn" size="small" @click="$emit('loss', asset)"> 盘亏 </van-button>
                <van-button v-if="showInventory" color="#3772ff" class="action-btn" size="small" @click="$emit('inventory', asset)"> 盘点 </van-button>
                <van-button v-if="showAgainInventory" plain color="#999" class="action-btn" size="small" @click="$emit('againinventory', asset)"> 重新盘点 </van-button>
                <van-button v-if="showDelete" plain color="#999" class="action-btn" size="small" @click="$emit('delete', asset)"> 删除 </van-button>
                <van-button v-if="showEdit" color="#3772ff" class="action-btn" size="small" @click="$emit('edit', asset)"> 编辑 </van-button>
                <van-button v-if="showReview" color="#3772ff" class="action-btn" size="small" @click="$emit('review', asset)"> 复核通过 </van-button>
                
            </div>
        </div>
        <!-- 任务事件 -->
        <div class="asset-card" v-if="currentTab == 'rwsj'">
            <div style="display: flex; justify-content: space-between">
                <div class="asset-name">{{ asset.createbyName }}</div>
                <div class="asset-name">{{ categorytype(asset.category) }}</div>
            </div>
            <div class="status-section">
                <div class="status-header">
                    <!-- <van-icon name="clock-o" size="16" color="#666" /> -->
                    <span class="status-text">{{ asset.remark }}</span>
                </div>
                <div class="status-detail" style="margin-left: 5px">
                    <div class="status-item2">
                        <van-icon name="clock-o" size="14" color="#999" />
                        <span class="status-value">{{ formatDT(asset.createDate) || '--' }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'assetCard',
    props: {
        asset: {
            type: Object,
            required: true,
            default: () => ({
                orgName: '',
                stocktakingResult: 0,
                stocktakingPersonName: '',
                stocktakingDate: '',
                reviewResult: 1,
                reviewPersonName: '',
                reviewDate: ''
            })
        },
        currentTab: {
            type: String,
            default: 'pdzc'
        },
        showDelete: {
            type: Boolean,
            default: false
        },
        showAgainInventory: {
            type: Boolean,
            default: false
        },
        showEdit: {
            type: Boolean,
            default: false
        },
        showLoss: {
            type: Boolean,
            default: false
        },
        showInventory: {
            type: Boolean,
            default: false
        },
        showReview: {
            type: Boolean,
            default: false
        },
        showDetail: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            mode: ''
        }
    },
    mounted() {},
    methods: {
        tasktype(v) {
            if (v === 0) return '待盘点'
            if (v === 1) return '盘盈'
            if (v === 2) return '盘亏'
            if (v === 3) return '信息变更'
        },
        categorytype(v) {
            let arr = ['-', '资产登记', '资产接收', '资产变更', '资产处置', '资产规划', '规划变更', '规划终止', '资产盘点']
            return arr[v]
        },
        reviewtype(v) {
            if (v === 0) return '待复核'
            if (v === 1) return '已复核'
        },
        formatDT(timestamp) {
            if (!timestamp) return '-'
            const date = new Date(Number(timestamp))
            const year = date.getFullYear()
            const month = (date.getMonth() + 1).toString().padStart(2, '0')
            const day = date.getDate().toString().padStart(2, '0')
            return `${year}-${month}-${day}`
        }
    }
}
</script>

<style scoped>
.asset-card-wrapper {
    margin-bottom: 12px;
}

.asset-card {
    width: 100%;
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    position: relative;
}

.asset-name {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    margin-bottom: 15px;
}

.status-section {
    margin-bottom: 15px;
}

.status-section:last-of-type {
    margin-bottom: 0;
}

.status-header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.status-text {
    margin-left: 6px;
    font-size: 14px;
    color: #333;
    font-weight: 500;
}

.status-detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-left: 22px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.double-icon-small {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.icon-overlap-small {
    position: absolute;
    left: 6px;
    z-index: 1;
}

.status-value {
    font-size: 13px;
    color: #999;
}

.action-buttons {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.action-btn {
    min-width: 60px;
    height: 25px;
    font-size: 14px;
    border-radius: 4px;
}
</style>
